import request from '@/utils/request'
import { otherFiltersItem } from '@/utils'

/**
 * 获取设计信息
 * @param {*} constCode
 * @returns
 */
export function getShopDesignInfo(constCode) {
  return request({
    url: `/api/v1/shopDesign/getShopDesign/${constCode}/info`,
    method: 'GET'
  })
}

/**
 * 修改重复设计数据
 * @param {object} data
 * @returns
 */
export function saveEditData(data) {
  return request({
    url: `/api/v1/shopDesignTask`,
    method: 'put',
    data
  })
}
/**
 * 获取全部设计详情
 * @param {*} params
 * @returns
 */
export function getShopDesignWholeInfo(id) {
  return request({
    url: `/api/v1/shopDesign/getShopDesign/${id}/wholeInfo`,
    method: 'GET'
  })
}
/**
 * 获取限时规则
 * @param {*} constRange
 * @param {*} matter
 * @param {*} minArea
 * @param {*} maxArea
 * @returns
 */
export function postConfigTimeLimitPage(constRange, matter, bizType) {
  const data = new FormData()
  data.append('filtersRaw', JSON.stringify([
    otherFiltersItem('constRange', constRange, '='),
    otherFiltersItem('timeLimitClass', 'PIC_DESIGN', '='),
    otherFiltersItem('matter', matter, 'like'),
    otherFiltersItem('bizType', `[${bizType}]`, 'in'),
    otherFiltersItem('enable', 1, '=')
  ]))
  data.append('pageFlag', false)
  return request({
    url: '/api/v1/configTimeLimit/page',
    method: 'POST',
    data
  })
}
/**
 * 新增设计任务
 * @param {*} data
 * @returns
 */
export function postAddShopDesignTask(data) {
  return request({
    url: '/api/v1/shopDesignTask/addShopDesignTask',
    method: 'POST',
    data
  })
}
/**
 * 获取基础信息
 * @param {*} id
 * @returns
 */
export function basicsInfo(id, isGenerate = 0) {
  return request({
    // url: `/api/v1/shopDesignTask/${id}/basicsInfo?isGenerate=${isGenerate}`,
    url: `/api/v1/shopDesignTask/${id}/basicsInfo?isGenerate=0`, // 后端改成全部传0
    method: 'GET'
  })
}
/**
 * 任务分配
 * @param {*} data
 * @returns
 */
export function putTaskAllocation(data) {
  return request({
    url: '/api/v1/shopDesignTask/taskAllocation',
    method: 'PUT',
    data
  })
}
/**
 * 获取设计任务信息
 * @param {*} id
 * @returns
 */
export function getShopDesignTaskInfo(id) {
  return request({
    url: `/api/v1/shopDesignTask/${id}/info`,
    method: 'GET'
  })
}
/**
 * 获取完整任务信息
 * @param {*} id
 * @returns
 */
export function getShopDesignTaskWholeInfo(id) {
  return request({
    url: `/api/v1/shopDesignTask/${id}/wholeInfo`,
    method: 'GET'
  })
}
/**
 * 任务处理
 * @param {*} data
 * @returns
 */
export function putTaskHandle(data) {
  return request({
    url: '/api/v1/shopDesignTask/taskHandle',
    method: 'PUT',
    data
  })
}
/**
 * 审核
 * @param {*} data
 * @returns
 */
export function putTaskExamine(data) {
  return request({
    url: '/api/v1/shopDesignTask/taskExamine',
    method: 'PUT',
    data
  })
}
/**
 * 图纸触发，获取来源图纸
 * @param {*} id
 * @returns
 */
export function getShopDesignPicture(id) {
  return request({
    url: `/api/v1/shopDesignPicture/${id}`,
    method: 'GET'
  })
}
/**
 * 根据门店建设号获取门店信息
 * @param {*} constCode
 * @returns
 */
export function shopConstructPage(constCode) {
  const data = new FormData()
  const filtersRaw = []
  filtersRaw.push(otherFiltersItem('constCode', constCode, '='))
  data.append('filtersRaw', JSON.stringify(filtersRaw))
  data.append('pageFlag', false)
  return request({
    url: '/api/v1/shopConstruct/allPage',
    method: 'POST',
    data
  })
}
/**
 * 根据门店建设项目号查询图纸
 * @param {*} constCode
 * @returns
 */
export function postGetPicture(constCode) {
  const data = new FormData()
  const filtersRaw = [
    otherFiltersItem('constCode', constCode, '='),
    otherFiltersItem('state', 'CANCELLATION', '<>')
  ]
  data.append('filtersRaw', JSON.stringify(filtersRaw))
  data.append('pageFlag', false)
  return request({
    url: '/api/v1/shopDesignPicture/getPicture/page1',
    method: 'POST',
    data
  })
}
/**
 * 获取图纸触发信息
 * @param {*} picTaskCode
 * @returns
 */
export function postGetPicturePage(picTaskCode) {
  const data = new FormData()
  data.append('pageFlag', false)
  data.append('filtersRaw', JSON.stringify([otherFiltersItem('picTaskCode', picTaskCode, '=')]))
  return request({
    url: '/api/v1/shopDesignPicture/getPicture/page1',
    method: 'POST',
    data
  })
}
/**
 * 详情获取变更记录
 * @param {*} id
 * @returns
 */
export function getPicinfo(id) {
  return request({
    url: `/api/v1/shopDesignTask/${id}/picinfo`,
    method: 'GET'
  })
}
/**
 * 获取区域配置
 * @returns
 */
export function getConfigArea(areaCode) {
  const data = new FormData()
  data.append('pageFlag', false)
  const filtersRaw = []
  filtersRaw.push(otherFiltersItem('areaCode', `[${areaCode}]`, 'in'))
  data.append('filtersRaw', JSON.stringify(filtersRaw))
  return request({
    url: `/api/v1/configArea/page`,
    method: 'POST',
    data
  })
}
/**
 * 获取所有区域
 * @returns
 */
export function getAllConfigArea() {
  return request({
    url: '/api/v1/configArea/',
    method: 'GET'
  })
}
/**
 * 获取所有设计单位
 */
export function getAllOrg9() {
  return request({
    url: '/api/v1/user/orgTreeByType?type=9',
    method: 'GET'
  })
}
